<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ include file="/webpage/include/taglib.jsp"%>
<%@ attribute name="id" type="java.lang.String" required="true" description="编号"%>
<%@ attribute name="name" type="java.lang.String" required="true" description="隐藏域名称（ID）"%>
<%@ attribute name="idx" type="java.lang.String" required="false" description="需要关联带入数据的input"%>
<%@ attribute name="value" type="java.lang.String" required="true" description="隐藏域值（ID）"%>
<%@ attribute name="labelName" type="java.lang.String" required="true" description="输入框名称（Name）"%>
<%@ attribute name="labelValue" type="java.lang.String" required="true" description="输入框值（Value）"%>
<%@ attribute name="fieldLabels" type="java.lang.String" required="true" description="表格Th里显示的名字"%>
<%@ attribute name="fieldKeys" type="java.lang.String" required="true" description="表格Td里显示的值"%>
<%@ attribute name="searchLabels" type="java.lang.String" required="true" description="检索框标签"%>
<%@ attribute name="searchKeys" type="java.lang.String" required="true" description="检索框key"%>
<%@ attribute name="title" type="java.lang.String" required="true" description="选择框标题"%>
<%@ attribute name="url" type="java.lang.String" required="true" description="数据地址"%>
<%@ attribute name="cssClass" type="java.lang.String" required="false" description="css样式"%>
<%@ attribute name="cssStyle" type="java.lang.String" required="false" description="css样式"%>
<%@ attribute name="isMultiSelected" type="java.lang.Boolean" required="false" description="是否允许多选"%>
<%@ attribute name="disabled" type="java.lang.String" required="false" description="是否限制选择，如果限制，设置为disabled"%>
<%@ attribute name="btnAdd" type="java.lang.String" required="false" description="输入框最后边的图片样式"%>
<%@ attribute name="dialogTitle" type="java.lang.String" required="false" description="弹窗名字"%>
<%@ attribute name="dialogUrl" type="java.lang.String" required="false" description="弹窗名字"%>
<%@ attribute name="dialogWidth" type="java.lang.String" required="false" description="弹窗名字"%>
<%@ attribute name="dialogHeight" type="java.lang.String" required="false" description="弹窗名字"%>
<input id="${id}Id" name="${name}"  type="hidden" value="${value}"/>
<div class="input-group" style="width: 100%">
	<input id="${id}Name"  name="${labelName }" ${allowInput?'':'readonly="readonly"'}  type="text" value="${labelValue}" data-msg-required="${dataMsgRequired}"
		   class="${cssClass}" style="${cssStyle}"/>
	<span class="input-group-btn">
	       		 <button type="button"  id="${id}Button" class="btn <c:if test="${fn:contains(cssClass, 'input-sm')}"> btn-sm </c:if><c:if test="${fn:contains(cssClass, 'input-lg')}"> btn-lg </c:if>  ${disabled} ${hideBtn ? 'hide' : ''}"><i class="fa ${btnAdd ? "fa-plus" : "fa-search"}"></i>
	             </button>
	               <button type="button" id="${id}DelButton" class="close" data-dismiss="alert" style="position: absolute; top: 5px; right: 53px; z-index: 999; display: block;">×</button>
       		 </span>

</div>
<label id="${id}Name-error" class="error" for="${id}Name" style="display:none"></label>
<script type="text/javascript">
	$(document).ready(function(){
		var b = "${btnAdd}";
		if(b != "" && b == "true"){
			$("#${id}Name").click(function(){
				if ($("#${id}Button").hasClass("disabled")){
					return true;
				}

				top.layer.open({
					type: 2,
					area: ['1000px', '500px'],
					title:"${title}",
					auto:true,
					name:'friend',
					content: "${ctx}/tag/gridselect?url="+encodeURIComponent("${url}")+"&fieldLabels="+encodeURIComponent("${fieldLabels}")+"&fieldKeys="+encodeURIComponent("${fieldKeys}")+"&searchLabels="+encodeURIComponent("${searchLabels}")+"&searchKeys="+encodeURIComponent("${searchKeys}")+"&isMultiSelected=${isMultiSelected? true:false}",
					btn: ['确定', '关闭'],
					yes: function(index, layero){
						var iframeWin = layero.find('iframe')[0].contentWindow; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
						var items = iframeWin.getSelections();
						if(items == ""){
							jp.warning("必须选择一条数据!");
							return;
						}
						var ids = [];
						var names = [];
						for(var i=0; i<items.length; i++){
							var item = items[i];
							ids.push(item.id);
							names.push(item${fn:substring(labelName, fns:lastIndexOf(labelName, '.'), fn:length(labelName))})
						}
						$("#${id}Id").val(ids.join(","));
						$("#${id}Name").val(names.join(","));
						putRelName2("${idx}",item)
						top.layer.close(index);//关闭对话框。
					},
					cancel: function(index){
					}
				});
			})

			$("#${id}Button").click(function(){
				jp.openSaveDialog('${dialogTitle}', "${ctx}${dialogUrl}",'${dialogWidth}', '${dialogHeight}');
			})

		}else {
			$("#${id}Button, #${id}Name").click(function(){

				if ($("#${id}Button").hasClass("disabled")){
					return true;
				}
				var urll;
				if('${idx}'==0){
					urll = '${url}?carzgcid=7e76ec64c9ce4b77862a6a01e4870d3c'
				}else {
					urll = '${url}?carzgcid=ff09c770d01d4807a9c3829538f93674'
				}
				top.layer.open({
					type: 2,
					area: ['1000px', '500px'],
					title:"${title}",
					auto:true,
					name:'friend',
					content: "${ctx}/tag/gridselect?url="+encodeURIComponent(urll)+"&fieldLabels="+encodeURIComponent("${fieldLabels}")+"&fieldKeys="+encodeURIComponent("${fieldKeys}")+"&searchLabels="+encodeURIComponent("${searchLabels}")+"&searchKeys="+encodeURIComponent("${searchKeys}")+"&isMultiSelected=${isMultiSelected? true:false}",
					btn: ['确定', '关闭'],
					yes: function(index, layero){
						var iframeWin = layero.find('iframe')[0].contentWindow; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
						var items = iframeWin.getSelections();
						if(items == ""){
							jp.warning("必须选择一条数据!");
							return;
						}
						var ids = [];
						var names = [];
						for(var i=0; i<items.length; i++){
							var item = items[i];
							ids.push(item.id);
							names.push(item${fn:substring(labelName, fns:lastIndexOf(labelName, '.'), fn:length(labelName))})
						}
						$("#${id}Id").val(ids.join(","));
						$("#${id}Name").val(names.join(","));
						putRelName2("${idx}",item)

						if(b == "search") {
							getSearch();
						}
						top.layer.close(index);//关闭对话框。
					},
					cancel: function(index){
					}
				});
			})
		}

		$("#${id}DelButton").click(function(){
			// 是否限制选择，如果限制，设置为disabled
			if ($("#${id}Button").hasClass("disabled")){
				return true;
			}
			// 清除
			$("#${id}Id").val("");
			$("#${id}Name").val("");
			$("#${id}Name").focus();

		});
	})

	function putRelName2(name,jb) {
		if(jb['id'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_archivesid').val(jb['id'])
		}
		if(jb['carzgcid'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_carzgcid').val(jb['carzgcid'])
		}
		if(jb['carzgcName'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_carzgcName').val(jb['carzgcName'])
		}
		if(jb['no'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_no').val(jb['no'])
		}
		if(jb['name'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_name').val(jb['name'])
		}
		if(jb['brand'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_brandid').val(jb['brand'].id)
			$('#usedcarxsarchivesmxList'+name+'_brandname').val(jb['brand'].name)
		}
		if(jb['typeclass'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_typeclassid').val(jb['typeclass'].id)
			$('#usedcarxsarchivesmxList'+name+'_typeclassname').val(jb['typeclass'].name)
		}
		if(jb['modell'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_modellid').val(jb['modell'].id)
			$('#usedcarxsarchivesmxList'+name+'_modellname').val(jb['modell'].name)
		}
		if(jb['qudongid'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_qudongid').val(jb['qudongid'])
		}
		if(jb['qudongName'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_qudongName').val(jb['qudongName'])
		}
		if(jb['zoushuid'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_zoushuid').val(jb['zoushuid'])
		}
		if(jb['zoushuName'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_zoushuName').val(jb['zoushuName'])
		}
		if(jb['ranyouid'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_ranyouid').val(jb['ranyouid'])
		}
		$('#usedcarxsarchivesmxList'+name+'_classid').val('销售合同')
		$('#usedcarxsarchivesmxList'+name+'_isnewcar').val('f791258de49b47d19ec501789e853750')
		if(jb['ranyouName'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_ranyouName').val(jb['ranyouName'])
		}
		if(jb['mali'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_mali').val(jb['mali'])
		}if(jb['ranyouid'] != undefined){

		}if(jb['fdjpp'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_fdjpp').val(jb['fdjpp'])
		}
		if(jb['pfbzid'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_pfbzid').val(jb['pfbzid'])
		}
		if(jb['pfbzName'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_pfbzName').val(jb['pfbzName'])
		}
		if(jb['shubi'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_shubi').val(jb['shubi'])
		}
		if(jb['quality'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_quality').val(jb['quality'])
		}
		if(jb['dangwei'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_dangwei').val(jb['dangwei'])
		}
		if(jb['dangweiName'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_dangweiName').val(jb['dangweiName'])
		}
		$('#usedcarxsarchivesmxList'+name+'_havegua').val('f791258de49b47d19ec501789e853750')
		if(jb['haveguaName'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_haveguaName').val(jb['haveguaName'])
		}
		if(jb['size'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_size').val(jb['size'])
		}
		if(jb['gonglishu'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_gonglishu').val(jb['gonglishu'])
		}
		if(jb['luohulx'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_luohulx').val(jb['luohulx'])
		}
		if(jb['luohulxName'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_luohulxName').val(jb['luohulxName'])
		}
		if(jb['address'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_addressid').val(jb['address'].id)
			$('#usedcarxsarchivesmxList'+name+'_addressname').val(jb['address'].name)
		}
		if(jb['spendxs'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_spendxs').val(jb['spendxs'])
		}
		if(jb['spendsg'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_spendsg').val(jb['spendsg'])
		}
		if(jb['datezc'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_datezc').data("DateTimePicker").date(jb['datezc']);
		}
		if(jb['datejqx'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_datejqx').data("DateTimePicker").date(jb['datejqx']);
		}
		if(jb['datesc'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_datesc').data("DateTimePicker").date(jb['datesc']);
		}
		if(jb['datesyx'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_datesyx').data("DateTimePicker").date(jb['datesyx']);
		}
		if(jb['dataxs'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_dataxs').data("DateTimePicker").date(jb['dataxs']);
		}
		if(jb['price'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_price').val(jb['price'])
		}
		if(jb['pricebj'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_pricebj').val(jb['pricebj'])
		}
		if(jb['memo'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_memo').val(jb['memo'])
		}
		if(jb['sglxid'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_sglxid').val(jb['sglxid'])
		}
		if(jb['locationid'] != undefined){
			$('#usedcarxsarchivesmxList'+name+'_locationid').val(jb['locationid'])
		}

	}
</script>
